package com.smedi.ismedi.progress.core.application.query.Impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smedi.ismedi.progress.core.application.command.VersionManageListQuery;
import com.smedi.ismedi.progress.core.application.command.VersionManageOneQuery;
import com.smedi.ismedi.progress.core.application.convert.AppConverter;
import com.smedi.ismedi.progress.core.application.query.VersionManageQueryService;
import com.smedi.ismedi.progress.core.domain.aggregatemodel.Progress;
import com.smedi.ismedi.progress.core.domain.aggregatemodel.VersionManage;
import com.smedi.ismedi.progress.core.domain.dto.VersionManageQuery;
import com.smedi.ismedi.progress.core.domain.repository.ProgressReportRepository;
import com.smedi.ismedi.progress.core.domain.repository.ProgressRepository;
import com.smedi.ismedi.progress.core.domain.repository.VersionManageRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 进度管理 查询实现类
 *
 * @author xienannan
 * @date 2021/08/28
 */
@Service
@AllArgsConstructor
public class VersionManageQueryServiceImpl implements VersionManageQueryService {
    private final AppConverter appConverter;
    private final ProgressRepository progressRepository;
    private final VersionManageRepository versionManageRepository;
    private final ProgressReportRepository progressReportRepository;

    @Override
    public Progress getVersionManageOne(VersionManageOneQuery versionManageOneQuery) {
        VersionManageQuery versionManageQuery =   appConverter.versionManageOneQueryToVersionManageQuery(versionManageOneQuery);
        return progressRepository.getVersionManageOne(versionManageQuery);
    }

    @Override
    public Page<VersionManage> getVersionList(VersionManageListQuery versionManageListQuery) {
        Page<VersionManage> page = versionManageRepository.getVersionList(versionManageListQuery);
        page.getRecords().forEach(v->{
            List<Long> constructionMemberIds =  progressReportRepository.getConstructionMemberByProjectId(v.getProjectId().longValue());
            v.setConstructionMember(constructionMemberIds);
        });
        return page;
    }

}
